package com.hz.friends.serverrequest;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.security.auth.callback.Callback;

import org.json.JSONException;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;

import com.alibaba.fastjson.JSONObject;
import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.AjaxStatus;
import com.avos.avoscloud.AVCloud;
import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVFile;
import com.avos.avoscloud.AVInstallation;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVPush;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.FindCallback;
import com.avos.avoscloud.FunctionCallback;
import com.avos.avoscloud.GetCallback;
import com.avos.avoscloud.ProgressCallback;
import com.avos.avoscloud.RefreshCallback;
import com.avos.avoscloud.SaveCallback;
import com.avos.avoscloud.SendCallback;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.hisun.phone.core.voice.CCPCall;
import com.hisun.phone.core.voice.Device;
import com.hisun.phone.core.voice.Device.State;
import com.hisun.phone.core.voice.DeviceListener;
import com.hisun.phone.core.voice.listener.OnIMListener;
import com.hisun.phone.core.voice.model.CloopenReason;
import com.hisun.phone.core.voice.model.im.IMAttachedMsg;
import com.hisun.phone.core.voice.model.im.IMDismissGroupMsg;
import com.hisun.phone.core.voice.model.im.IMInviterMsg;
import com.hisun.phone.core.voice.model.im.IMJoinGroupMsg;
import com.hisun.phone.core.voice.model.im.IMProposerMsg;
import com.hisun.phone.core.voice.model.im.IMQuitGroupMsg;
import com.hisun.phone.core.voice.model.im.IMRemoveMemeberMsg;
import com.hisun.phone.core.voice.model.im.IMReplyJoinGroupMsg;
import com.hisun.phone.core.voice.model.im.IMTextMsg;
import com.hisun.phone.core.voice.model.im.InstanceMsg;
import com.hisun.phone.core.voice.model.setup.UserAgentConfig;
import com.hz.friends.application.CustomApplication;
import com.hz.friends.chat.Helper.CCPConfig;
import com.hz.friends.chat.Helper.CCPHelper;
import com.hz.friends.chat.Helper.CCPIntentUtils;
import com.hz.friends.chat.entity.IMChatMessage;
import com.hz.friends.db.DBContactUser;
import com.hz.friends.db.DBMessageManager;
import com.hz.friends.global.Global;
import com.hz.friends.serverrequest.ALEngineConfig.CallBack;
import com.hz.friends.serverrequest.ALPushCenter.ALPushType;
import com.hz.friends.utils.MLog;
import com.hz.friends.utils.UtilTools;

public class ALCCPEngine implements OnIMListener {

	// protected static final Object Boolean = null;
	//
	// static int DEFAULE_LIMITE = 20;

	// 单例
	private static ALCCPEngine ccpEngine = null;

	private ArrayList<HashMap<String, Object>> sendedMsgList;
	private ArrayList<String> receivedMsgList1;
	private ArrayList<String> receivedMsgList2;


	public static ALCCPEngine defauleEngine() {
		if (ccpEngine == null) {
			ccpEngine = new ALCCPEngine();
			if (CCPHelper.getInstance().getDevice() != null) {
				CCPHelper.getInstance().getDevice().setOnIMListener(ccpEngine);
			}
			ccpEngine.sendedMsgList = new ArrayList<HashMap<String, Object>>();
			ccpEngine.receivedMsgList1 = new ArrayList<String>();
			ccpEngine.receivedMsgList2 = new ArrayList<String>();
		}
		return ccpEngine;
	}

	public enum ALGroupType {

		ALGroupTypeOfNone("未知", 0), ALGroupTypeOfNews("新闻", 1), ALGroupTypeOfBusiness(
				"商务", 2), ALGroupTypeOfFood("美食", 3), ALGroupTypeOfChat("娱乐", 4), ALGroupTypeOfEntertainMent(
				"闲聊", 5);

		private int _value;
		private String _name;

		private ALGroupType(String name, int value) {
			_name = name;
			_value = value;
		}

		public String get_name() {
			return _name;
		}

		public int get_value() {
			return _value;
		}
	}
    
    public enum ALCommandType {
		
		ALCommandTypeOfUndefine("未知",0),
		ALCommandTypeOfAddBan("屏蔽",1),
		ALCommandTypeOfRemoveBan("取消屏蔽",2);
		
	    private int _value;
	    private String _name;
	    
	    private ALCommandType(String name, int value)
	    {
	    	_name = name;
	    	_value = value;
	    }
        
	    public String get_name() {
			return _name;
		}
	    
		public int get_value() {
			return _value;
		}
		
		public static ALCommandType get_type(int i){
			ALCommandType type = null;
			switch (i) {
                case 0:
                    type = ALCommandTypeOfUndefine;
                    break;
                case 1:
                    type = ALCommandTypeOfAddBan;
                    break;
                case 2:
                    type = ALCommandTypeOfRemoveBan;
                    break;
                    //			case 3:
                    //				type = ALPushTypeOfGift;
                    //				break;
                    //			case 4:
                    //				type = ALPushTypeOfMessageOfBBs; 
                    //				break;
                    //			case 5:
                    //				type = ALPushTypeOfSpecialRemind; 
                    //				break;
                default:
                    break;
			}
			return type;
		}
	} 


	public enum ALMessageOfChatType {

		ALMessageOfChatTypeOfUndefine("未知", 0), 
		ALMessageOfChatTypeOfText("文字", 1), 
		ALMessageOfChatTypeOfVoice("声音", 2), 
		ALMessageOfChatTypeOfImage("图片", 3), 
		ALMessageOfChatTypeOfVideo("视频", 4), 
		
		ALMessageOfChatTypeOfGroupInvite("群邀请",5),
		
		ALMessageOfChatTypeOfLocation("位置",6),
		ALMessageOfChatTypeOfFile("文件",7),
		ALMessageOfChatTypeOfCommand("命令",8),
	
		ALMessageOfChatTypeOfFollow("关注",10),
		ALMessageOfChatTypeOfLeaveMessage("留言",11),
		ALMessageOfChatTypeOfReceiveGift("接到礼物",12);

		private final int _value;
		private final String _name;

		private ALMessageOfChatType(String name, int value) {
			_name = name;
			_value = value;
		}

		public String get_name() {
			return _name;
		}

		public int get_value() {
			return _value;
		}

		public static ALMessageOfChatType get_type(int i) {
			ALMessageOfChatType type = null;
			switch (i) {
			case 0:
				type = ALMessageOfChatTypeOfUndefine;
				break;
			case 1:
				type = ALMessageOfChatTypeOfText;
				break;
			case 2:
				type = ALMessageOfChatTypeOfVoice;
				break;
			case 3:
				type = ALMessageOfChatTypeOfImage;
				break;
			case 4:
				type = ALMessageOfChatTypeOfVideo;
				break;
			case 5:
				type = ALMessageOfChatTypeOfGroupInvite;
				break;
			case 6:
				type = ALMessageOfChatTypeOfLocation;
				break;
			case 7:
				type = ALMessageOfChatTypeOfFile;
				break;
			case 8:
				type = ALMessageOfChatTypeOfCommand;
				break;
			case 10:
				type = ALMessageOfChatTypeOfFollow;
				break;
			case 11:
				type = ALMessageOfChatTypeOfLeaveMessage;
				break;
			case 12:
				type = ALMessageOfChatTypeOfReceiveGift;
				break;
			default:
				break;
			}
			return type;
		}
	}

	

	// 刷新user属性
	public void logIn(AVUser user, final CallBack boolCallback) {
		if (!user.isAuthenticated()) {
			return;
		}

		user.refreshInBackground("subAccountSid,subToken,voipAccount,voipPwd",
				new RefreshCallback<AVObject>() {

					@Override
					public void done(AVObject obj, AVException e) {
						boolCallback.done(obj, e);
					}
				});
	}

	public void signUp(AVUser user, final CallBack boolCallback) {

		if (!user.isAuthenticated()) {
			boolCallback.done(false, new AVException(110, "未认证用户"));
			return;
		}

		AVCloud.callFunctionInBackground("cloopenSignUp", null,
				new FunctionCallback<Boolean>() {

					@Override
					public void done(Boolean success, AVException e) {
						boolCallback.done(success, e);
					}
				});
	}

	public Boolean isLoggedIn() {
		return CCPHelper.getInstance().getDevice().isOnline()
				.equals(State.ONLINE)
				&& AVUser.getCurrentUser().isAuthenticated();
	}

	public void createGroup(String name, String coverURL, ALGroupType chatType,
			String declared, double latitude, double longitude, float distance,
			String place, Boolean isHidden, final CallBack objectCallback) {

		if (!AVUser.getCurrentUser().isAuthenticated()) {
			objectCallback.done(null, new AVException(110, "未认证用户"));
			return;
		}

		if (name == null || Math.abs(latitude) > 90
				|| Math.abs(longitude) > 180) {
			objectCallback.done(null, new AVException(113, "参数错误"));
			return;
		}

		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("name", name);
		if (coverURL != null)
			params.put("coverURL", coverURL);
		params.put("chatType", chatType.get_value());
		if (declared != null)
			params.put("declared", declared);
		params.put("latitude", latitude);
		params.put("longitude", longitude);
		params.put("distance", distance);
		if (place != null)
			params.put("place", place);
		params.put("isHidden", isHidden);

		AVCloud.callFunctionInBackground("ccpCreateGroup", params,
				new FunctionCallback<String>() {

					@Override
					public void done(String groupObjId, AVException e) {
						// TODO Auto-generated method stub
						if (groupObjId != null && e == null) {
							AVObject.createWithoutData("Group", groupObjId)
									.fetchInBackground(
											new GetCallback<AVObject>() {

												@Override
												public void done(
														AVObject group,
														AVException e) {
													// TODO Auto-generated
													// method stub
													objectCallback.done(group,
															e);
												}
											});
						} else {
							objectCallback.done(null, e);
						}
					}
				});
	}

	// updateGroup
	public void updateGroup(AVObject group, final String name,
			final String coverURL, final ArrayList<AVObject> photos,
			final ALGroupType chatType, final String declared,
			final Boolean isHidden, final CallBack boolCallback) {

		final AVUser user = AVUser.getCurrentUser();
		if (!user.isAuthenticated()) {
			boolCallback.done(false, new AVException(110, "未登陆"));
			return;
		}

		group.fetchIfNeededInBackground("creater", new GetCallback<AVObject>() {

			@Override
			public void done(AVObject obj, AVException e) {
				// TODO Auto-generated method stub
				if (obj != null
						|| obj.getList("administrators").contains(
								user.getObjectId())
						|| user.getObjectId().equals(
								obj.getAVUser("creater").getObjectId())) {
					if (name != null)
						obj.put("name", name);
					if (coverURL != null)
						obj.put("coverURL", coverURL);
					if (chatType != null)
						obj.put("chatType", chatType.get_value());
					if (declared != null)
						obj.put("declared", declared);
					obj.put("isHidden", isHidden);
					if (photos != null && photos.size() > 0) {
						for (AVObject photo : photos) {
							if (photo.getObjectId() != null
									&& "Photo".equals(photo.getClassName())) {
								obj.getRelation("album").add(photo);
							}
						}
					}
					obj.saveEventually(new SaveCallback() {

						@Override
						public void done(AVException e) {
							// TODO Auto-generated method stub
							boolCallback.done(e == null, e);
						}
					});
				} else {
					boolCallback.done(false, new AVException(113, "未认证用户"));
				}
			}
		});

	}

	// 解散聊天室 destroyGroup
	public void destroyGroup(AVObject group, final CallBack boolCallback) {

		final AVUser user = AVUser.getCurrentUser();
		if (!user.isAuthenticated()) {
			boolCallback.done(false, new AVException(110, "未登陆"));
			return;
		}

		if (group == null || !"Group".equals(group.getClassName())
				|| group.getObjectId() == null) {
			boolCallback.done(false, new AVException(112, "参数错误"));
			return;
		}

		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("groupObjId", group.getObjectId());

		AVCloud.callFunctionInBackground("ccpDestroyGroup", params,
				new FunctionCallback<Boolean>() {

					@Override
					public void done(java.lang.Boolean success, AVException e) {
						// TODO Auto-generated method stub
						boolCallback.done(e == null, e);
					}
				});
	}

	public void getMemberOfGroup(AVObject group, final CallBack listCallback) {

		if (!this.isLoggedIn()) {
			listCallback.done(null, new AVException(110, "未登陆"));
			return;
		}

		if (group == null || !"Group".equals(group.getClassName())
				|| group.getObjectId() == null) {
			listCallback.done(null, new AVException(112, "参数错误"));
			return;
		}

		group.fetchInBackground("groupId", new GetCallback<AVObject>() {

			@Override
			public void done(AVObject group, AVException e) {
				// TODO Auto-generated method stub
				if (e != null || group == null) {
					listCallback.done(null, e);
					return;
				}

				HashMap<String, Object> params = new HashMap<String, Object>();
				params.put("groupId", group.getString("groupId"));
				AVCloud.callFunctionInBackground("ccpGetMemberOfGroup", params,
						new FunctionCallback<ArrayList<AVObject>>() {

							@Override
							public void done(ArrayList<AVObject> userIds,
									AVException e) {
								// TODO Auto-generated method stub
								if (e != null || userIds == null
										|| userIds.size() == 0) {
									listCallback.done(null, e);
									return;
								}

								AVQuery<AVUser> userQ = new AVQuery<AVUser>(
										"_User");
								userQ.whereContainedIn("objectId", userIds);
								userQ.findInBackground(new FindCallback<AVUser>() {

									@Override
									public void done(List<AVUser> users,
											AVException e) {
										// TODO Auto-generated method stub
										listCallback.done(users, e);
									}
								});
							}
						});
			}
		});

	}

	// 查看附近的群列表 getGroupListWithNear
	public void getGroupListWithNear(double latitude, double longitude,
			float distance, ALGroupType groupType, int limit,
			ArrayList<AVObject> notContainedInGroups,
			final CallBack listCallback) {

		if (listCallback != null) {
			ArrayList<String> groups = new ArrayList<String>();
			for (AVObject group : notContainedInGroups) {
				if ("Group".equals(group.getClassName())
						&& group.getObjectId() != null) {
					groups.add(group.getObjectId());
				}
			}

			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put("groupType", groupType.get_value());
			params.put("latitude", latitude);
			params.put("longitude", longitude);
			params.put("distance", distance);
			params.put("notContained", groups);
			params.put("limit", limit);

			AVCloud.callFunctionInBackground("getNearGroup", params,
					new FunctionCallback<ArrayList<String>>() {

						@Override
						public void done(ArrayList<String> groupObjIds,
								AVException e) {
							// TODO Auto-generated method stub
							if (groupObjIds != null && e == null) {
								ArrayList<AVObject> groupList = new ArrayList<AVObject>();
								for (String groupObjId : groupObjIds) {
									groupList.add(AVObject.createWithoutData(
											"Group", groupObjId));
								}
								AVObject.fetchAllInBackground(groupList,
										new FindCallback<AVObject>() {

											@Override
											public void done(
													List<AVObject> groups,
													AVException e) {
												// TODO Auto-generated method
												// stub
												listCallback.done(groups, e);
											}
										});
							} else {
								listCallback.done(null, e);
							}
						}
					});
		}
	}

	// 查看热门的群列表
	public void getGroupListOfHot(ALGroupType groupType, int limit,
			ArrayList<AVObject> notContainedInGroups,
			final CallBack listCallback) {

		if (listCallback != null) {
			ArrayList<String> groups = new ArrayList<String>();
			for (AVObject group : notContainedInGroups) {
				if ("Group".equals(group.getClassName())
						&& group.getObjectId() != null) {
					groups.add(group.getObjectId());
				}
			}

			AVQuery<AVObject> groupQ = AVQuery.getQuery("Group");
			if (groupType != ALGroupType.ALGroupTypeOfNone)
				groupQ.whereEqualTo("groupType", groupType.get_value());
			if (groups.size() != 0)
				groupQ.whereNotContainedIn("objectId", groups);
			if (limit > 0)
				groupQ.limit(limit);
			groupQ.orderByDescending("hot");
			groupQ.findInBackground(new FindCallback<AVObject>() {

				@Override
				public void done(List<AVObject> groupList, AVException e) {
					// TODO Auto-generated method stub
					listCallback.done(groupList, e);
				}
			});

		}
	}

	// 用户进入过得的群
	public void getGroupListOfEnter(AVUser user, final CallBack listCallback) {
		if (listCallback != null) {
			if (user == null || user.getObjectId() == null
					|| !"_User".equals(user.getClassName())) {
				listCallback.done(false, new AVException(112, "参数错误"));
				return;
			}

			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put("userId", user.getObjectId());

			AVCloud.callFunctionInBackground("getUserEnterGroupList", params,
					new FunctionCallback<ArrayList<String>>() {

						@Override
						public void done(ArrayList<String> groupObjIds,
								AVException e) {
							// TODO Auto-generated method stub
							if (groupObjIds != null && e == null) {
								ArrayList<AVObject> groupList = new ArrayList<AVObject>();
								for (String groupObjId : groupObjIds) {
									groupList.add(AVObject.createWithoutData(
											"Group", groupObjId));
								}
								AVObject.fetchAllInBackground(groupList,
										new FindCallback<AVObject>() {

											@Override
											public void done(
													List<AVObject> groups,
													AVException e) {
												// TODO Auto-generated method
												// stub
												listCallback.done(groups, e);
											}
										});
							} else {
								listCallback.done(null, e);
							}
						}
					});
		}
	}

	// 进入群 enterGroup
	public void enterGroup(AVObject group, final CallBack boolCallback) {

		AVUser user = AVUser.getCurrentUser();
		if (user.getString("subAccountSid") == null
				|| user.getString("subToken") == null) {
			boolCallback.done(false, new AVException(111, "用户参数错误"));
			return;
		}

		if (group == null || !"Group".equals(group.getClassName())
				|| group.getObjectId() == null) {
			boolCallback.done(false, new AVException(112, "参数错误"));
			return;
		}

		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("groupObjId", group.getObjectId());
		// params.put("subAccountSid", subAccountSid);

		// params.put("subToken", subToken);

		AVCloud.callFunctionInBackground("ccpEnterGroup", params,
				new FunctionCallback<Boolean>() {

					@Override
					public void done(java.lang.Boolean success, AVException e) {
						boolCallback.done(e == null, e);
					}
				});
	}

	// 退出群 exitGroup
	public void exitGroup(AVObject group,
	// String subAccountSid,
	// String subToken,
			final CallBack boolCallback) {

		AVUser user = AVUser.getCurrentUser();
		if (user.getString("subAccountSid") == null
				|| user.getString("subToken") == null) {
			boolCallback.done(false, new AVException(111, "用户参数错误"));
			return;
		}

		if (group == null || !"Group".equals(group.getClassName())
				|| group.getObjectId() == null) {
			boolCallback.done(false, new AVException(112, "参数错误"));
			return;
		}

		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("groupObjId", group.getObjectId());
		// params.put("subAccountSid", subAccountSid);
		// params.put("subToken", subToken);

		AVCloud.callFunctionInBackground("ccpExitGroup", params,
				new FunctionCallback<Boolean>() {

					@Override
					public void done(java.lang.Boolean success, AVException e) {
						// TODO Auto-generated method stub
						boolCallback.done(e == null, e);
					}
				});
	}

	/**
	 * 上传文件
	 * 
	 * @param imageData
	 *            文件数据 <Data>
	 * @param resultBlock
	 *            返回文件地址 <String>
	 * @param progressBlock
	 *            进度 <int>
	 */
	private void uploadFileData(String fileName, byte[] fileData,
			final CallBack progressBlock, final CallBack fileCallback) {

		final AVFile file = new AVFile(fileName, fileData);
		file.saveInBackground(new SaveCallback() {

			@Override
			public void done(AVException e) {
				// TODO Auto-generated method stub

				fileCallback.done(file.getUrl(), e);
			}
		}, new ProgressCallback() {

			@Override
			public void done(Integer progress) {
				// TODO Auto-generated method stub
				progressBlock.done(progress, null);
			}
		});
	}

	private void uploadFilePath(String fileName, String filePath,
			final CallBack progressBlock, final CallBack fileCallback) {

		try {
			final AVFile file = AVFile
					.withAbsoluteLocalPath(fileName, filePath);
			file.saveInBackground(new SaveCallback() {

				@Override
				public void done(AVException e) {
					// TODO Auto-generated method stub
					fileCallback.done(file, e);
				}
			}, new ProgressCallback() {

				@Override
				public void done(Integer progress) {
					// TODO Auto-generated method stub
					progressBlock.done(progress, null);
				}
			});
		} catch (Exception e) {
			// TODO Auto-generated catch block
			fileCallback.done(null, new AVException(e.getCause()));
		}
	}

	/**
	 * 上传照片到相册
	 * 
	 * @param thePhotos
	 * @param resultBlock
	 */
	public void updateAlbumOfGroup(AVObject group,
			final ArrayList<AVObject> thePhotos, final CallBack boolCallback) {
		this._changeGroupAlbumWithGroup(group, true, thePhotos, boolCallback);
	}

	/**
	 * 删除照片到相册
	 * 
	 * @param thePhotos
	 *            Photo
	 * @param resultBlock
	 */
	public void deleteAlbumOfGroup(AVObject group,
			final ArrayList<AVObject> thePhotos, final CallBack boolCallback) {
		this._changeGroupAlbumWithGroup(group, false, thePhotos, boolCallback);
	}

	/**
	 * 查看相册album
	 * 
	 * @param resultBlock
	 */
	public void getAlbumOfGroup(AVObject group, final int limit,
			final CallBack listCallback) {
		group.fetchIfNeededInBackground(new GetCallback<AVObject>() {

			@Override
			public void done(AVObject group, AVException e) {
				// TODO Auto-generated method stub
				if (e != null) {
					listCallback.done(null, e);
				} else {
					AVQuery<AVObject> albumQ = group.getRelation("album")
							.getQuery();
					if (limit > 0)
						albumQ.limit(limit);
					albumQ.whereNotEqualTo("isDeleted", true);
					albumQ.orderByDescending("createdAt");
					albumQ.findInBackground(new FindCallback<AVObject>() {

						@Override
						public void done(List<AVObject> photos, AVException e) {
							// TODO Auto-generated method stub
							listCallback.done(photos, e);
						}
					});
				}
			}
		});
	}

	private Boolean _isLoggedIn() {
		return AVUser.getCurrentUser().isAuthenticated();// && 云通讯判断
	}

	/**
	 * 发送消息
	 * 
	 * @param theContent
	 *            文本<String> 音频<Data> 图片地址<String>或数据<Data>
	 *            视频地址<String>或数据<Data>
	 * @param theTargets
	 *            个人<User> 或 群组<Group>
	 * @param theType
	 *            content的类型 <enum>
	 * @param resultBlock
	 *            发送是否成功 <BOOL>
	 */
	private void _changeGroupAlbumWithGroup(AVObject group,
			final Boolean isAdd, final ArrayList<AVObject> thePhotos,
			final CallBack boolCallback) {
		if (!this._isLoggedIn()) {
			boolCallback.done(false, new AVException(110, "请先登录"));
			return;
		}

		if (group.getObjectId() == null || thePhotos == null
				|| thePhotos.size() == 0) {
			boolCallback.done(false, new AVException(111, "参数错误"));
			return;
		}

		group.fetchIfNeededInBackground(new GetCallback<AVObject>() {

			@Override
			public void done(AVObject group, AVException e) {
				// TODO Auto-generated method stub
				for (AVObject photo : thePhotos) {
					if (photo.getObjectId() != null) {
						if (isAdd) {
							group.getRelation("album").add(photo);
						} else {
							group.getRelation("album").remove(photo);
						}
					}
				}
				group.saveInBackground(new SaveCallback() {

					@Override
					public void done(AVException e) {
						// TODO Auto-generated method stub
						boolCallback.done(e == null, e);
					}
				});
			}
		});
	}

	public void getVoipFromObject(AVObject object, final CallBack stringCallback) {
		if (object == null || object.getObjectId() == null) {
			stringCallback.done(null, new AVException(111, "参数错误"));
			return;
		}

		object.fetchIfNeededInBackground("voipAccount,groupId",
				new GetCallback<AVObject>() {

					@Override
					public void done(AVObject obj, AVException e) {
						// TODO Auto-generated method stub
						String voip = obj.getString("voipAccount");
						if (voip == null) {
							voip = obj.getString("groupId");
						}
						stringCallback.done(voip, e);
					}
				});
	}

	
	/**
	 * 发送消息
	 * 
	 * @param theContent
	 *            文本<String> 音频<Data> 图片地址<String>或数据<Data>
	 *            视频地址<String>或数据<Data>
	 * @param theTarget
	 *            个人<User> 或 群组<Group>
	 * @param theType
	 *            content的类型 <enum>
	 * @param resultBlock
	 *            发送是否成功 <BOOL>
	 */
	// 生成 userData
	public void postMessageOfText(final String text, final AVObject target,
			final CallBack boolCallback) {

		if (!this._isLoggedIn()) {
			boolCallback.done(false, new AVException(777001, "没有登录"));
			return;
		}

		this.getVoipFromObject(target, new CallBack() {

			@Override
			public void done(Object object, AVException e) {
				// TODO Auto-generated method stub
				if (e != null || object == null) {
					boolCallback.done(false, new AVException(777221,
							"对方尚未开通IM服务"));
					return;
				} else {
					HashMap<String, Object> userData = new HashMap<String, Object>();
					userData.put("url", text);
					userData.put("type",
							ALMessageOfChatType.ALMessageOfChatTypeOfText
									.get_value());
					ALCCPEngine.this._postMessage(userData, target,
							(String) object, boolCallback);
				}
			}
		});
	}

	public void postMessageOfVoicePath(final String voicePath,
			final long duration, final AVObject target,
			final CallBack boolCallback) {

		if (!this._isLoggedIn()) {
			boolCallback.done(false, new AVException(777001, "没有登录"));
			return;
		}

		this.getVoipFromObject(target, new CallBack() {

			@Override
			public void done(final Object object, AVException e) {
				// TODO Auto-generated method stub
				if (e != null || object == null) {
					boolCallback.done(false, new AVException(777221,
							"对方尚未开通IM服务"));
					return;
				} else {
					final AVFile file;
					try {
						file = AVFile.withAbsoluteLocalPath("voice.amr",
								voicePath);
						file.saveInBackground(new SaveCallback() {

							@Override
							public void done(AVException e) {
								// TODO Auto-generated method stub
								if (e != null) {
									boolCallback.done(false, e);
								} else {
									HashMap<String, Object> userData = new HashMap<String, Object>();
									userData.put("url", file.getUrl());
									userData.put("duration", duration);
									userData.put(
											"type",
											ALMessageOfChatType.ALMessageOfChatTypeOfVoice
													.get_value());
									ALCCPEngine.this._postMessage(userData,
											target, (String) object,
											boolCallback);
								}
							}
						});

					} catch (Exception e1) {
						// TODO Auto-generated catch block
						boolCallback.done(false, new AVException(e1.getCause()));
					}
				}
			}
		});
	}

	public void postMessageOfVoiceData(final byte[] voiceData,
			final long duration, final AVObject target,
			final CallBack boolCallback) {

		if (!this._isLoggedIn()) {
			boolCallback.done(false, new AVException(777001, "没有登录"));
			return;
		}

		this.getVoipFromObject(target, new CallBack() {

			@Override
			public void done(final Object object, AVException e) {
				// TODO Auto-generated method stub
				if (e != null || object == null) {
					boolCallback.done(false, new AVException(777221,
							"对方尚未开通IM服务"));
					return;
				} else {
					final AVFile file = new AVFile("voice.amr", voiceData);
					file.saveInBackground(new SaveCallback() {

						@Override
						public void done(AVException e) {
							// TODO Auto-generated method stub
							if (e != null) {
								boolCallback.done(false, e);
							} else {
								HashMap<String, Object> userData = new HashMap<String, Object>();
								userData.put("url", file.getUrl());
								userData.put("duration", duration);
								userData.put(
										"type",
										ALMessageOfChatType.ALMessageOfChatTypeOfVoice
												.get_name());
								ALCCPEngine.this._postMessage(userData, target,
										(String) object, boolCallback);
							}
						}
					});
				}
			}
		});
	}

	public void postMessageOfImagePath(final String imagePath, final int width,
			final int height, final AVObject target, final CallBack boolCallback) {

		if (!this._isLoggedIn()) {
			boolCallback.done(false, new AVException(777001, "没有登录"));
			return;
		}

		this.getVoipFromObject(target, new CallBack() {

			@Override
			public void done(final Object object, AVException e) {
				// TODO Auto-generated method stub
				if (e != null || object == null) {
					boolCallback.done(false, new AVException(777221,
							"对方尚未开通IM服务"));
					return;
				} else {
					final AVFile file;
					try {
						file = AVFile.withAbsoluteLocalPath("image.png",
								imagePath);
						file.saveInBackground(new SaveCallback() {

							@Override
							public void done(AVException e) {
								// TODO Auto-generated method stub
								if (e != null) {
									boolCallback.done(false, e);
								} else {
									HashMap<String, Object> userData = new HashMap<String, Object>();
									userData.put("url", file.getUrl());
									userData.put("size", "{" + width + ","
											+ height + "}");
									userData.put(
											"type",
											ALMessageOfChatType.ALMessageOfChatTypeOfImage
													.get_value());
									ALCCPEngine.this._postMessage(userData,
											target, (String) object,
											boolCallback);
								}
							}
						});

					} catch (Exception e1) {
						// TODO Auto-generated catch block
						boolCallback.done(false, new AVException(e1.getCause()));
					}
				}
			}
		});
	}

	public void postMessageOfImageData(final byte[] imageData,
			final float width, final float height, final AVObject target,
			final CallBack boolCallback) {

		if (!this._isLoggedIn()) {
			boolCallback.done(false, new AVException(777001, "没有登录"));
			return;
		}

		this.getVoipFromObject(target, new CallBack() {

			@Override
			public void done(final Object object, AVException e) {
				// TODO Auto-generated method stub
				if (e != null || object == null) {
					boolCallback.done(false, new AVException(777221,
							"对方尚未开通IM服务"));
					return;
				} else {
					final AVFile file = new AVFile("image.png", imageData);
					file.saveInBackground(new SaveCallback() {

						@Override
						public void done(AVException e) {
							// TODO Auto-generated method stub
							if (e != null) {
								boolCallback.done(false, e);
							} else {
								HashMap<String, Object> userData = new HashMap<String, Object>();
								userData.put("url", file.getUrl());
								userData.put("size", "{" + width + "," + height
										+ "}");
								userData.put(
										"type",
										ALMessageOfChatType.ALMessageOfChatTypeOfImage
												.get_name());
								ALCCPEngine.this._postMessage(userData, target,
										(String) object, boolCallback);
							}
						}
					});
				}
			}
		});
	}

	public void postMessageOfVideoPath(final String videoPath,
			final long duration, final AVObject target,
			final CallBack boolCallback) {

		if (!this._isLoggedIn()) {
			boolCallback.done(false, new AVException(777001, "没有登录"));
			return;
		}

		this.getVoipFromObject(target, new CallBack() {

			@Override
			public void done(final Object object, AVException e) {
				// TODO Auto-generated method stub
				if (e != null || object == null) {
					boolCallback.done(false, new AVException(777221,
							"对方尚未开通IM服务"));
					return;
				} else {
					final AVFile file;
					try {
						file = AVFile.withAbsoluteLocalPath("video.mp4",
								videoPath);
						file.saveInBackground(new SaveCallback() {

							@Override
							public void done(AVException e) {
								// TODO Auto-generated method stub
								if (e != null) {
									boolCallback.done(false, e);
								} else {
									HashMap<String, Object> userData = new HashMap<String, Object>();
									userData.put("url", file.getUrl());
									userData.put("duration", duration);
									userData.put(
											"type",
											ALMessageOfChatType.ALMessageOfChatTypeOfVideo
													.get_value());
									ALCCPEngine.this._postMessage(userData,
											target, (String) object,
											boolCallback);
								}
							}
						});

					} catch (Exception e1) {
						// TODO Auto-generated catch block
						boolCallback.done(false, new AVException(e1.getCause()));
					}
				}
			}
		});
	}

	public void postMessageOfVideoData(final byte[] videoData,
			final long duration, final AVObject target,
			final CallBack boolCallback) {

		if (!this._isLoggedIn()) {
			boolCallback.done(false, new AVException(777001, "没有登录"));
			return;
		}

		this.getVoipFromObject(target, new CallBack() {

			@Override
			public void done(final Object object, AVException e) {
				// TODO Auto-generated method stub
				if (e != null || object == null) {
					boolCallback.done(false, new AVException(777221,
							"对方尚未开通IM服务"));
					return;
				} else {
					final AVFile file = new AVFile("video.mp4", videoData);
					file.saveInBackground(new SaveCallback() {

						@Override
						public void done(AVException e) {
							// TODO Auto-generated method stub
							if (e != null) {
								boolCallback.done(false, e);
							} else {
								HashMap<String, Object> userData = new HashMap<String, Object>();
								userData.put("url", file.getUrl());
								userData.put("duration", duration);
								userData.put(
										"type",
										ALMessageOfChatType.ALMessageOfChatTypeOfVideo
												.get_name());
								ALCCPEngine.this._postMessage(userData, target,
										(String) object, boolCallback);
							}
						}
					});
				}
			}
		});
	}

	public void postMessageForInvite(final AVUser user, final AVObject group,
			final String message, final CallBack boolCallback) {

		if (!this._isLoggedIn()) {
			boolCallback.done(false, new AVException(777001, "没有登录"));
			return;
		}

		if (group == null || group.getObjectId() == null) {
			boolCallback.done(false, new AVException(777011, "参数错误"));
			return;
		}

		this.getVoipFromObject(user, new CallBack() {

			@Override
			public void done(Object object, AVException e) {
				// TODO Auto-generated method stub
				if (e != null || object == null) {
					boolCallback.done(false, new AVException(777221,
							"对方尚未开通IM服务"));
					return;
				} else {
					HashMap<String, Object> userData = new HashMap<String, Object>();
					userData.put("url", group.getObjectId());
					if (message != null)
						userData.put("message", message);
					userData.put(
							"type",
							ALMessageOfChatType.ALMessageOfChatTypeOfGroupInvite
									.get_value());
					ALCCPEngine.this._postMessage(userData, user,
							(String) object, boolCallback);
				}
			}
		});
	}
    
	/*
	 * 发送命令
	 */
    private void postMessageOfCommand(
		      final ALCommandType commandType,
		      final AVObject toTargat,
		      final CallBack boolCallback){
		
		if (!this._isLoggedIn())
		{
			boolCallback.done(false,new AVException(777001, "没有登录"));
			return;
		}
		
		if (toTargat==null || toTargat.getObjectId()==null)
		{
			boolCallback.done(false,new AVException(777011, "参数错误"));
			return;
		}
		
		this.getVoipFromObject(toTargat, new CallBack() {
			
			@Override
			public void done(Object object, AVException e) {
				// TODO Auto-generated method stub
				String toVoip = (String)object;
				
				if (e!=null || toVoip==null || toVoip.length()==0)
				{
					boolCallback.done(false,new AVException(777221, "对方尚未开通IM服务"));
					return;
				}
				else
				{
					Boolean isGroup = false;
					if (toVoip.startsWith("g"))
					{
						isGroup = true;
					}
					
					HashMap<String, Object> messaege = new HashMap<String, Object>();
					messaege.put("isGroup", isGroup);
					messaege.put("type", ALMessageOfChatType.ALMessageOfChatTypeOfCommand.get_value());
					
					HashMap<String, Object> userData = new HashMap<String, Object>();
					userData.put("isGroup", isGroup);
					userData.put("commandType", commandType.get_value());
					
					if (!isGroup)
					{
						userData.put("fromId", AVUser.getCurrentUser().getObjectId());
					}
					else
					{
						userData.put("fromId", toTargat.getObjectId());
					}
					
					// 发送消息
					String msgId = CCPHelper.getInstance().getDevice().sendInstanceMessage(toVoip, messaege.toString(), userData.toString(), null);
					if (msgId!=null)
					{
						HashMap<String, Object> sendMsgInfo = new HashMap<String, Object>();
						sendMsgInfo.put("type", ALMessageOfChatType.ALMessageOfChatTypeOfCommand.get_value());
						sendMsgInfo.put("msgId", msgId);
						sendMsgInfo.put("isGroup", isGroup);
						sendMsgInfo.put("block", boolCallback);
						ALCCPEngine.this.sendedMsgList.add(sendMsgInfo);
					}
					else
					{
						boolCallback.done(false,null);
					}
				}
			}
		});
		
	}

	// 生成moc
	private void _postMessage(
			final HashMap<String, Object> userData,
			final AVObject target, final String toVoip,
			final CallBack boolCallback) {

		if ("_User".equals(target.getClassName())) 
		{
			ALUserEngine.defauleEngine().isBanByMyWithUser((AVUser) target,new CallBack() {

						@Override
						public void done(Object object, AVException e) {
							// TODO Auto-generated method stub
							if (e != null)
							{
								boolCallback.done(false, e);
							} 
							else 
							{
								final AVObject moc = new AVObject(
										"MessageOfChat");
								moc.put("type", userData.get("type"));
								moc.put("fromUser", ALEngineConfig.user());
								moc.put("isDeleted", false);
								moc.put("userData", userData);
								moc.put("isBaned", object);

								// if (toVoip.startsWith("g"))
								// {
								// moc.put("group", target);
								// }
								// else
								// {
								moc.put("toUser", target);
								// }

								moc.saveInBackground(new SaveCallback() {

									@Override
									public void done(AVException e) {
										// TODO Auto-generated method stub
										if (e != null) {
											boolCallback.done(false, e);
										} else {
											ALCCPEngine.this.__postMessage(moc,
													userData, toVoip,
													boolCallback);
										}
									}
								});
							}
						}
					});
		} else if ("Group".equals(target.getClassName())) {
			final AVObject moc = new AVObject("MessageOfChat");
			moc.put("type", userData.get("type"));
			moc.put("fromUser", ALEngineConfig.user());
			moc.put("isDeleted", false);
			moc.put("userData", userData);
			// moc.put("isBaned", object);

			// if (toVoip.startsWith("g"))
			// {
			moc.put("group", target);
			// }
			// else
			// {
			// moc.put("toUser", target);
			// }

			moc.saveInBackground(new SaveCallback() {

				@Override
				public void done(AVException e) {
					// TODO Auto-generated method stub
					if (e != null) {
						boolCallback.done(false, e);
					} else {
						ALCCPEngine.this.__postMessage(moc, userData, toVoip,
								boolCallback);
					}
				}
			});
		} else {
			boolCallback.done(false, new AVException(777114, "参数错误"));
		}
	}

	private void __postMessage(AVObject moc, HashMap<String, Object> userData,
			String toVoip, final CallBack boolCallback) {

		if (toVoip == null) {
			boolCallback.done(false, null);
			return;
		}

		Boolean isGroup = false;
		if (toVoip.startsWith("g")) {
			isGroup = true;
		}

		// 发送消息
		JSONObject message = new JSONObject();
		message.put("mocId", moc.getObjectId());
		message.put("isGroup", isGroup);
		message.put("type", moc.getInt("type"));

		String msgId = CCPHelper.getInstance().getDevice()
				.sendInstanceMessage(toVoip, message.toString(), null, null);
		if (msgId != null) {
			HashMap<String, Object> sendMsgInfo = new HashMap<String, Object>();
			sendMsgInfo.put("type", moc.getInt("type"));
			sendMsgInfo.put("msgId", msgId);
			sendMsgInfo.put("moc", moc);
			sendMsgInfo.put("isGroup", isGroup);
			sendMsgInfo.put("block", boolCallback);
			this.sendedMsgList.add(sendMsgInfo);
		} else {
			boolCallback.done(false, null);
		}

	}

	// 处理发送的文字IM
	private void _senderTextMessage(
			IMTextMsg textMsg, 
			CloopenReason reason) {

		for (HashMap<String, Object> sendMsgInfo : this.sendedMsgList) {
			String msgId = (String) sendMsgInfo.get("msgId");

			if (msgId == null) {
				continue;
			}

			if (textMsg.getMsgId().equals(msgId)) 
			{

				final int type = ((Integer) sendMsgInfo.get("type"));

				if (type != ALMessageOfChatType.ALMessageOfChatTypeOfCommand.get_value()) 
				{

					final AVObject moc = (AVObject) sendMsgInfo.get("moc");
					Boolean isGroup = (Boolean) sendMsgInfo.get("isGroup");

					// 个人聊天(群组没有聊天记录)
					if (!isGroup && moc != null && moc.getObjectId() != null) {
						/*
						 * 插入本地 数据库
						 */
						
						/*
						 * 发通知
						 */
						ALPushCenter.isClosePushAlert(AVUser.getCurrentUser(), new CallBack() {

							@Override
							public void done(Object obj, AVException e) {
								// TODO Auto-generated method stub
								if (e==null && (Boolean)obj!=true)
								{
									AVQuery<AVInstallation> installQ = AVInstallation.getQuery();
									installQ.whereEqualTo("user", moc.getAVUser("toUser"));

									ALPushCenter.sendPush(installQ, ALPushType.ALPushTypeOfMessageOfChat, type);
								}
							}
						});
					}
				}

				CallBack boolCallback = (CallBack) sendMsgInfo.get("block");

				if (reason.getReasonCode() == 0) {
					boolCallback.done(true, null);
				} else {
					boolCallback.done(
							false,
							new AVException(reason.getReasonCode(), reason
									.getMessage()));
				}

				this.sendedMsgList.remove(sendMsgInfo);
				return;

			}
		}
	}

	private void _receivedTextMessage(IMTextMsg textMsg) {

		JSONObject message = JSONObject.parseObject(textMsg.getMessage());
		
		ALMessageOfChatType type = (ALMessageOfChatType)message.get("type");
		Boolean isGroup = message.getBoolean("isGroup");
		
		Intent intent = new Intent(CCPIntentUtils.INTENT_IM_SAVE_AND_SENT);
		
//		HashMap<String, Object> userDataMap = new HashMap<String, Object>();
//		userDataMap.put("isGroup", isGroup);
		
		intent.putExtra("isGroup", isGroup);
		
		if (type.equals(ALMessageOfChatType.ALMessageOfChatTypeOfCommand))
		{
			JSONObject userData = JSONObject.parseObject(textMsg.getUserData());
			ALCommandType commandType = ALCommandType.get_type(userData.getIntValue("commandType"));
			String fromId = userData.getString("fromId");

//			userDataMap.put("type", type);
//			userDataMap.put("commandType", commandType);
//			userDataMap.put("fromId", fromId);
			
			intent.putExtra("type", type);
			intent.putExtra("commandType", commandType);
			intent.putExtra("fromId", fromId);
		}
		else
		{
			String mocId = message.getString("mocId");

			Boolean isExsit = false;
			for (String receivedMsgId : this.receivedMsgList1) 
			{
				if (receivedMsgId.equals(mocId)) 
				{
					isExsit = true;
				}
			}

			for (String receivedMsgId : this.receivedMsgList2) 
			{
				if (receivedMsgId.equals(mocId)) {
					isExsit = true;
				}
			}

			if (isExsit)
				return;

			// 2个都满了 清除1 加入1
			// if (this.receivedMsgList1.size()>=100 &&
			// this.receivedMsgList2.size()>=100)
			// {
			// this.receivedMsgList1.clear();
			// this.receivedMsgList1.add(mocId);
			// }

			// 1满了 2没满 加入2
			if (this.receivedMsgList1.size() >= 100) {
				if (this.receivedMsgList2.size() >= 99) {
					this.receivedMsgList1.clear();
				}
				this.receivedMsgList2.add(mocId);
			}
			// 1没满 2满了 加入1
			else if (this.receivedMsgList2.size() >= 100) {
				if (this.receivedMsgList1.size() >= 99) {
					this.receivedMsgList2.clear();
				}
				this.receivedMsgList1.add(mocId);
			}
			// 都不满 加入1
			else {
				this.receivedMsgList1.add(mocId);
			}

//			AVObject moc = AVObject.createWithoutData("MessageOfChat", mocId);
			
			intent.putExtra("type", type);
			intent.putExtra("mocId", mocId);
		}

		CustomApplication.getInstance().sendBroadcast(intent);
		
//		// 个人聊天
//		if (!isGroup) 
//		{	
//			/*
//			* 加入本地聊天记录
//			*/
//			
//			//通知保存并分发消息
//			Intent intent = new Intent(CCPIntentUtils.INTENT_IM_SAVE_AND_SENT);
//			intent.putExtra("msgObjId", mocId);
//			intent.putExtra("isGroup", false);
//			CustomApplication.getInstance().sendBroadcast(intent);
//		}
//		// 群组聊天
//		else 
//		{
//			Intent intent = new Intent(CCPIntentUtils.INTENT_IM_RECIVE);
//			intent.putExtra("msgObjId", mocId);
//			intent.putExtra("isGroup", true);
//			CustomApplication.getInstance().sendBroadcast(intent);
//		}

	}



	/**
	 * 获得全部未读的聊天记录数
	 * 
	 * @param resultBlock
	 *            未读的聊天记录数 <int>
	 */
	public void getALLUnreadMessageCount(final CallBack intCallback) {

	}

	/**
	 * 获得全部联系人
	 * 
	 * @param resultBlock
	 *            全部联系人 <int>
	 */
	public void getAllContacts(int limit, ArrayList<AVObject> notContainedIn,
			final CallBack listCallback) {

	}

	/**
	 * 
	 * 删除联系人
	 */
	public void deleteContactWithObject(final AVUser user,
			final CallBack boolCallback) {

	}

	/**
	 * 
	 * 获取与某用户的聊天记录
	 * 
	 * @param theUser
	 *            会话的对象 <User>
	 * @param theLimit
	 *            返回条数 <int>
	 * @param theLessThanDate
	 *            返回的时间节点（只返回时间点之前的） <date>
	 * @param resultBlock
	 *            聊天记录 <MessageOfChat>
	 */

	public void getMessageOfChat(final AVObject target, int limit,
			Date lessThanDate, final CallBack listCallback) {

		AVQuery<AVObject> mocQ = new AVQuery<AVObject>();

		if ("Group".equals(target.getClassName())) {
			mocQ = AVQuery.getQuery("MessageOfChat");
			mocQ.whereEqualTo("group", target);
		} else if ("_User".equals(target.getClassName())) {
			AVQuery<AVObject> mocQ1 = AVQuery.getQuery("MessageOfChat");
			mocQ1.whereEqualTo("toUser", target);

			AVQuery<AVObject> mocQ2 = AVQuery.getQuery("MessageOfChat");
			mocQ2.whereEqualTo("fromUser", target);

			ArrayList<AVQuery<AVObject>> subQ = new ArrayList<AVQuery<AVObject>>();
			subQ.add(mocQ1);
			subQ.add(mocQ2);
			mocQ = AVQuery.or(subQ);
		} else {
			listCallback.done(null, new AVException(113, "参数错误"));
		}

		if (limit > 0)
			mocQ.limit(limit);
		if (lessThanDate != null)
			mocQ.whereLessThan("createdAt", lessThanDate);
		mocQ.whereNotEqualTo("isDeleted", true);
		mocQ.orderByDescending("createdAt");
		this._includeKeyWithMessage(mocQ);
		mocQ.findInBackground(new FindCallback<AVObject>() {

			@Override
			public void done(List<AVObject> mocs, AVException e) {
				// TODO Auto-generated method stub
				listCallback.done(mocs, e);
			}
		});
	}

	private void _includeKeyWithMessage(AVQuery<AVObject> mocQ) {
		mocQ.include("fromUser");
	}

	// 发送IM消息回调
	@Override
	public void onSendInstanceMessage(CloopenReason reason, InstanceMsg msg) {
		MLog.i("MyTag",
				"====onSendInstanceMessage reason iserror:" + reason.isError()
						+ " msg instanceof IMTextMsg:"
						+ (msg instanceof IMTextMsg));

		if (msg != null && msg instanceof IMTextMsg) {
			this._senderTextMessage((IMTextMsg) msg, reason);
		}
	}

	// 收到InstanceMessage消息
	public void onReceiveInstanceMessage(InstanceMsg msg) {

		if (msg != null && msg instanceof IMTextMsg) {
			this._receivedTextMessage((IMTextMsg) msg);

		}

	}

	@Override
	public void onConfirmIntanceMessage(
			com.hisun.phone.core.voice.model.CloopenReason arg0) {
		// TODO Auto-generated method stub

	}

	// 下载IM附件回调
	@Override
	public void onDownloadAttached(
			com.hisun.phone.core.voice.model.CloopenReason arg0, String arg1) {
		// TODO Auto-generated method stub

	}

	// 播放录音结束回调
	@Override
	public void onFinishedPlaying() {
		// TODO Auto-generated method stub

	}

	// 录音振幅回调
	@Override
	public void onRecordingAmplitude(double arg0) {
		// TODO Auto-generated method stub

	}

	// 录音超时回调
	@Override
	public void onRecordingTimeOut(long arg0) {
		// TODO Auto-generated method stub

	}
	
	
	public static void clear(){
		ccpEngine = null;
	}

}
